using System;
using System.ComponentModel;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Be.Timvw.Framework.ComponentModel
{
    [TestClass]
    public class WhenGettingFromPropertyDescriptorHelper
    {
        [TestMethod]
        public void ShouldReturnPropertyDescriptorWhenPropertyExists()
        {
            PersonWithIdWithoutName person = new PersonWithIdWithoutName();
            PropertyDescriptor propertyDescriptor = PropertyDescriptorHelper.Get(person, "Id");

            Type actualType = propertyDescriptor.PropertyType;
            string actualName = propertyDescriptor.Name;

            Type expectedType = typeof(int);
            string expectedName = "Id";

            Assert.AreEqual(expectedType, actualType);
            Assert.AreEqual(expectedName, actualName);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void ShouldThrowWhenPropertyDoesNotExist()
        {
            PersonWithIdWithoutName person = new PersonWithIdWithoutName();
            PropertyDescriptorHelper.Get(person, "Name");
        }
    }
}